<?php


namespace App\Http\Server;


use App\Models\Customer;
use App\Services\QueryService;

class CustomerServer
{
    /**
     * 添加客户
     * @param $customer_name
     * @param $customer_address
     * @param $customer_phone
     * @param $another_name
     */
    public function addCustomerServer($id,$customer_name,$customer_address,$customer_phone,$another_name,$province,$city,$county,$town,$village,$team,$wheat){
        if(isset($id) && !empty($id)){
            $model = Customer::find($id);
        }else{
            $model = new Customer();
        }
        $model->customer_name = $customer_name;
        $model->customer_address = $customer_address;
        $model->customer_phone = $customer_phone;
        $model->another_name = $another_name;
        if(!empty($province)){
            $model->province = $province;
        }
        if(!empty($city)){
            $model->city = $city;
        }
        $model->county = $county;
        $model->town = $town;
        $model->village = $village;
        $model->team = $team;
        $model->wheat = $wheat;
        $model->save();
        $customer = Customer::where('customer_phone',$customer_phone)->first();
        return ['status'=>200,'data'=>$customer,'msg'=>'success'];
    }

    /**
     * 获取客户列表
     * @param $customer_name
     * @param $customer_phone
     */
    public function getCustomerListServer($params,$per_page=10)
    {
        // 执行查询
        $users = Customer::Search($params)->with(['county','town','village'])->paginate($per_page);

        return ['status'=>200,'data'=>$users,'msg'=>'success'];
    }

    public function getCustomerInfoServer($id){
        $info = Customer::where('id',$id)->with(['county','town','village'])->first();
        return ['status'=>200,'data'=>$info,'msg'=>'success'];
    }


}
